'\" te
.\"  Copyright 1989 AT&T  Copyright (c) 2005, Sun Microsystems, Inc.  All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH CKRANGE 1 "Nov 4, 2005"
.SH NAME
ckrange, errange, helprange, valrange \- prompts for and validates an integer
.SH SYNOPSIS
.LP
.nf
\fBckrange\fR [\fB-Q\fR] [\fB-W\fR \fIwidth\fR] [\fB-l\fR \fIlower\fR] [\fB-u\fR \fIupper\fR] [\fB-b\fR \fIbase\fR]
     [\fB-d\fR \fIdefault\fR] [\fB-h\fR \fIhelp\fR] [\fB-e\fR \fIerror\fR] [\fB-p\fR \fIprompt\fR]
     [\fB-k\fR \fIpid\fR [\fB-s\fR \fIsignal\fR]]
.fi

.LP
.nf
\fB/usr/sadm/bin/errange\fR [\fB-W\fR \fIwidth\fR] [\fB-e\fR \fIerror\fR] [\fB-l\fR \fIlower\fR]
     [\fB-u\fR \fIupper\fR] [\fB-b\fR \fIbase\fR]
.fi

.LP
.nf
\fB/usr/sadm/bin/helprange\fR [\fB-W\fR \fIwidth\fR] [\fB-h\fR \fIhelp\fR] [\fB-l\fR \fIlower\fR]
     [\fB-u\fR \fIupper\fR] [\fB-b\fR \fIbase\fR]
.fi

.LP
.nf
\fB/usr/sadm/bin/valrange\fR [\fB-l\fR \fIlower\fR] [\fB-u\fR \fIupper\fR] [\fB-b\fR \fIbase\fR] \fIinput\fR
.fi

.SH DESCRIPTION
.sp
.LP
The \fBckrange\fR utility prompts a user for an integer between a specified
range and determines whether this response is valid. It defines, among other
things, a prompt message whose response should be an integer in the range
specified, text for help and error messages, and a default value (which is
returned if the user responds with a RETURN).
.sp
.LP
This command also defines a range for valid input. If either the lower or upper
limit is left undefined, then the range is bounded on only one end.
.sp
.LP
All messages are limited in length to 79 characters and are formatted
automatically. Tabs and newlines are removed after a single whitespace
character in a message definition, but spaces are not removed. When a tilde is
placed at the beginning or end of a message definition, the default text will
be inserted at that point, allowing both custom text and the default text to be
displayed.
.sp
.LP
If the prompt, help or error message is not defined, the default message (as
defined under EXAMPLES) is displayed.
.sp
.LP
Three visual tool modules are linked to the \fBckrange\fR command. They are
\fBerrange\fR (which formats and displays an error message on the standard
output), \fBhelprange\fR (which formats and displays a help message on the
standard output), and \fBvalrange\fR (which validates a response).
.sp
.LP
\fBNote:\fR Negative "input" arguments confuse \fBgetopt\fR in \fBvalrange\fR.
By inserting a "\(mi" before the argument, \fBgetopt\fR processing will stop.
See \fBgetopt\fR(1) and \fBIntro\fR(1) about \fBgetopt\fR parameter handling.
\fBgetopt\fR is used to parse positional parameters and to check for legal
options.
.SH OPTIONS
.sp
.LP
The following options are supported:
.sp
.ne 2
.na
\fB\fB-b\fR \fIbase\fR\fR
.ad
.RS 14n
Defines the base for input. Must be 2 to 36, default is 10. Base conversion
uses \fBstrtol\fR(3C). Output is always base 10.
.RE

.sp
.ne 2
.na
\fB\fB-d\fR \fIdefault\fR\fR
.ad
.RS 14n
Defines the default value as \fIdefault\fR. \fIdefault\fR is converted using
\fBstrtol\fR(3C) in the desired base. Any characters invalid in the specified
base will terminate the \fBstrtol\fR conversion without error.
.RE

.sp
.ne 2
.na
\fB\fB-e\fR \fIerror\fR\fR
.ad
.RS 14n
Defines the error message as \fI error\fR.
.RE

.sp
.ne 2
.na
\fB\fB-h\fR \fIhelp\fR\fR
.ad
.RS 14n
Defines the help message as \fI help\fR.
.RE

.sp
.ne 2
.na
\fB\fB-k\fR \fIpid\fR\fR
.ad
.RS 14n
Specifies that process \fBID\fR \fIpid\fR is to be sent a signal if the user
chooses to quit.
.RE

.sp
.ne 2
.na
\fB\fB-l\fR \fIlower\fR\fR
.ad
.RS 14n
Defines the lower limit of the range as \fIlower\fR. Default is the machine's
largest negative long.
.RE

.sp
.ne 2
.na
\fB\fB-p\fR \fIprompt\fR\fR
.ad
.RS 14n
Defines the prompt message as \fIprompt\fR.
.RE

.sp
.ne 2
.na
\fB\fB-Q\fR\fR
.ad
.RS 14n
Specifies that quit will not be allowed as a valid response.
.RE

.sp
.ne 2
.na
\fB\fB-s\fR \fIsignal\fR\fR
.ad
.RS 14n
Specifies that the process \fBID\fR \fIpid\fR defined with the \fB-k\fR option
is to be sent signal \fIsignal\fR when quit is chosen. If no signal is
specified,  \fBSIGTERM\fR is used.
.RE

.sp
.ne 2
.na
\fB\fB-u\fR \fIupper\fR\fR
.ad
.RS 14n
Defines the upper limit of the range as \fIupper\fR. Default is the machine's
largest positive long.
.RE

.sp
.ne 2
.na
\fB\fB-W\fR \fIwidth\fR\fR
.ad
.RS 14n
Specifies that prompt, help and error messages will be formatted to a line
length of \fIwidth\fR.
.RE

.SH OPERANDS
.sp
.LP
The following operand is supported:
.sp
.ne 2
.na
\fB\fIinput\fR\fR
.ad
.RS 9n
Input to be verified against upper and lower limits and base.
.RE

.SH EXAMPLES
.LP
\fBExample 1 \fRDefault base 10 prompt
.sp
.LP
The default base 10 prompt for \fBckrange\fR is:

.sp
.in +2
.nf
example% \fBckrange\fR
Enter an integer between \fIlower_bound \fRand
\fIupper_bound \fR[\fIlower_bound\(miupper_bound\fR,?,q]:
.fi
.in -2
.sp

.LP
\fBExample 2 \fRDefault base 10 error message
.sp
.LP
The default base 10 error message is:

.sp
.in +2
.nf
example% \fB/usr/sadm/bin/errange\fR
ERROR: Please enter an integer between \fIlower_bound \e\fR
     and \fIupper_bound\fR.
.fi
.in -2
.sp

.LP
\fBExample 3 \fRDefault base 10 help message
.sp
.LP
The default base 10 help message is:

.sp
.in +2
.nf
example% \fB/usr/sadm/bin/helprange\fR
Please enter an integer between \fIlower_bound\fR and \fIupper_bound\fR.
.fi
.in -2
.sp

.LP
\fBExample 4 \fRChanging messages for a base other than 10
.sp
.LP
The messages are changed from ``integer'' to ``base \fIbase\fR integer'' if the
base is set to a number other than 10. For example,

.sp
.in +2
.nf
example% \fB/usr/sadm/bin/helprange -b 36\fR
.fi
.in -2
.sp

.LP
\fBExample 5 \fRUsing the quit option
.sp
.LP
When the quit option is chosen (and allowed), \fBq\fR is returned along with
the return code \fB3\fR. Quit input gets a trailing newline.

.LP
\fBExample 6 \fRUsing the valrange module
.sp
.LP
The \fBvalrange\fR module will produce a usage message on stderr. It returns
\fB0\fR for success and non-zero for failure.

.sp
.in +2
.nf
example% \fB/usr/sadm/bin/valrange\fR
usage: valrange [-l lower] [-u upper] [-b base] input
.fi
.in -2
.sp

.SH EXIT STATUS
.sp
.LP
The following exit values are returned:
.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 5n
Successful execution.
.RE

.sp
.ne 2
.na
\fB\fB1\fR\fR
.ad
.RS 5n
\fBEOF\fR on input, or negative width on \fB-W\fR option, or usage error.
.RE

.sp
.ne 2
.na
\fB\fB2\fR\fR
.ad
.RS 5n
Usage error.
.RE

.sp
.ne 2
.na
\fB\fB3\fR\fR
.ad
.RS 5n
User termination (quit).
.RE

.SH SEE ALSO
.sp
.LP
.BR Intro (1),
.BR getopt (1),
.BR strtol (3C),
.BR signal.h (3HEAD),
.BR attributes (7)
